// 传引用调用的猫与狗程序: 引用参数

#include <iostream>
using namespace std;

// 获取宠物信息
void GetPetInfo(bool& hasDog, int& dogNum, bool& hasCat, int& catNum);

void WritePetInfo(bool hasDog, int dogNum, bool hasCat, int catNum);

int main() {
    bool hasDog;
    int dogNum;

    bool hasCat;
    int catNum;

    GetPetInfo(hasDog, dogNum, hasCat, catNum);

    WritePetInfo(hasDog, dogNum, hasCat, catNum);

    if (!hasDog && !hasCat) {
        cout << "你难道不喜欢宠物吗?\n";
    }
}

void GetPetInfo(bool& hasDog, int& dogNum, bool& hasCat, int& catNum) {
    hasDog = false;
    dogNum = 0;

    hasCat = false;
    catNum = 0;

    char ch;

    cout << "你养狗了吗? y=是,n=否: ";
    cin >> ch;
    if ('y' == ch) {
        cout << "你有几条狗: ";
        cin >> dogNum;
        hasDog = true;
    }

    cout << "你养猫了吗? y=是,n=否: ";
    cin >> ch;
    if ('y' == ch) {
        cout << "你有几只猫: ";
        cin >> catNum;
        hasCat = true;
    }
}

void WritePetInfo(bool hasDog, int dogNum, bool hasCat, int catNum) {
    cout << "狗和猫的饲养数据:\n";

    if (hasDog) {
        cout << "你养了 " << dogNum << " 条狗\n";
    }
    else {
        cout << "你未养狗。\n";
    }

    if (hasCat) {
        cout << "你养了 " << catNum << " 只猫\n";
    }
    else {
        cout << "你未养猫。\n";
    }
}
